<template>
  <div class="box">
    <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
      <el-radio-button v-show="isCollapse" :label="false">></el-radio-button>
      <el-radio-button v-show="!isCollapse" :label="true" class="shouqi"
        >收起</el-radio-button
      >
    </el-radio-group>
    <el-menu
      default-active="1-4-1"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      :collapse="isCollapse"
      router
      unique-opened
    >
      <el-submenu
        v-for="(item, index) in navMenuList"
        :key="index"
        :index="item.title"
      >
        <template slot="title">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.title }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            v-for="(childItem, num) in item.children"
            :key="num"
            :index="childItem.path"
            >{{ childItem.title }}</el-menu-item
          >
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "AsideView",
  props: [],
  data() {
    return {
      isCollapse: false,
      navMenuList: [
        {
          title: "用户管理",
          icon: "el-icon-user-solid",
          children: [
            {
              title: "用户列表",
              path: "/user",
            },
          ],
        },
        {
          title: "权限管理",
          icon: "el-icon-key",
          children: [
            { title: "角色列表", path: "/roles" },
            { title: "权限列表", path: "/rights" },
          ],
        },
        {
          title: "商品管理",

          icon: "el-icon-goods",
          children: [
            { title: "商品列表", path: "/goods" },
            { title: "分类参数", path: "/params" },
            { title: "商品分类", path: "/categories" },
          ],
        },
        {
          title: "订单管理",
          icon: "el-icon-s-order",
          children: [{ title: "订单列表", path: "/orders" }],
        },
        {
          title: "数据统计",
          icon: "el-icon-data-line",
          children: [{ title: "数据报表", path: "/ToTuBiao" }],
        },
      ],
    };
  },

  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    // 控制左侧折叠菜单开合
    changeStatus() {
      this.$bus.$on("change", (data) => {
        this.isCollapse = data.value;
      });
    },
  },
  mounted() {
    this.changeStatus();
  },
};
</script>

<style lang="scss" scoped>
.box {
  position: relative;

  .kaiguan {
    position: absolute;
    top: 0;
    left: 100px;
  }

  :deep(.el-menu-vertical-demo.el-menu) {
    .el-submenu__title {
      padding: 0;
      width: 200px;
    }
  }

  :deep(.el-menu-vertical-demo.el-menu--collapse.el-menu) {
    .el-submenu__title {
      padding: 0;
      width: 100%;
    }
  }
}

:deep(.el-radio-group) {
  width: 100%;

  .el-radio-button {
    width: 100%;

    .el-radio-button__inner {
      width: 100%;
      border: none;
      background: #409eff;
    }
  }
}
</style>